/*
 * File     : StructureRecord.java
 * Created  : 23 Apr 2011
 *
 * Copyright © 2011 Matthew Wilson (mj. {my-surname} .uk {at} gmail.com)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.googlecode.dni.internal.structure;

import com.googlecode.dni.type.structure.StructureFactory;
import com.googlecode.dni.type.structure.StructureInfo;

/**
 * <p>
 *  Encapsulates information about a structure.
 * </p>
 *
 * @author Matthew Wilson
 */
public final class StructureRecord
{

    /**
     * Marker value when a structure implementation is being created.
     */
    public static final StructureRecord IN_PROGRESS = new StructureRecord();

    private final Class< ? > type;

    private final Class< ? > implType;

    private final StructureFactory< ? > factory;

    private final StructureInfo info;

    private final int largestFieldUnitSize;

    /**
     * @param type
     *            the interface type
     * @param implType
     *            the implementation type
     * @param factory
     *            the structure factory
     * @param info
     *            the structure info
     * @param largestFieldUnitSize
     *            the largest field unit size; used for padding calculations
     */
    public StructureRecord( final Class< ? > type,
                            final Class< ? > implType,
                            final StructureFactory< ? > factory,
                            final StructureInfo info,
                            final int largestFieldUnitSize )
    {
        this.type = type;
        this.implType = implType;
        this.factory = factory;
        this.info = info;
        this.largestFieldUnitSize = largestFieldUnitSize;
    }

    /**
     * Creates a new marker instance.
     */
    private StructureRecord()
    {
        this.type = null;
        this.implType = null;
        this.factory = null;
        this.info = null;
        this.largestFieldUnitSize = 0;
    }

    /**
     * @return the interface type
     */
    public Class< ? > getType()
    {
        return this.type;
    }

    /**
     * @return the implementation type
     */
    public Class< ? > getImplType()
    {
        return this.implType;
    }

    /**
     * @return the structure factory
     */
    public StructureFactory< ? > getFactory()
    {
        return this.factory;
    }

    /**
     * @return the structure info
     */
    public StructureInfo getInfo()
    {
        return this.info;
    }

    /**
     * @return the largest field unit size
     */
    public int getLargestFieldUnitSize()
    {
        return this.largestFieldUnitSize;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString()
    {
        return "[" + this.type.getName() + ", " + this.implType.getName() + ", " + this.factory.getClass().getName() + "]";
    }

}
